<template>
    <div class='cold'>
        <div class='buttons'>
            <el-button @click="add">新增冰柜</el-button>
        </div>
        <div class='content'>
            <div class='item' v-for="(item,index) in items" :key="index">
                <div class='title'>
                    {{item.type}}
                </div>
                <div class='item_contents'>
                    <div   v-for="(item_,index2) in item.data " :key="index2" :class="item_.className" @dblclick="openLcdblClick(item_)" :style="{'background':item_.color}">
                        <div class='box-title' :style="{'borderBottomColor':item_.fontColor1}">
                            <div class='box-no'  :style="{'color':item_.fontColor1}">
                                {{item_.lg_ex12 ? item_.lg_eX12:item_.lg_no+"号"}}
                            </div>
                            <div class='box-name' :style="{'color':item_.fontColor2}">
                                <span style='font-weight:bold'>{{item_.sz_ex3}}</span>
                                <br/>
                                <span>{{item_.sz_ex4}}</span>
                                <span style='margin-left:5px'>{{item_.sz_ex5}}</span>
                            </div>
                        </div>
                        <div class='box-content' :style="{'color':item_.fontColor2}">
                            <div >编号：{{item_.sz_ex2}}</div>
                            <div >地址：{{item_.sz_addr}}</div>
                            <div v-if="item_.lg_ex4!=''" :class="item_.lg_ex5=='报警' ? 'waringwd':'wd'">温度：{{item_.lg_ex4}}</div>
                            <div v-if="item_.lg_ex4!=''" :class="item_.lg_ex5=='报警' ? 'waringwd':'wd'">状态：{{item_.lg_ex5=="" ? "正常":item_.lg_ex5}}</div>
                        </div>
                        <div class='box-footer isEdit' v-if="item_.sz_id!=''" :style="{'color':item_.fontColor3,'borderTopColor':item_.fontColor1}">
                            <div style='width:50px'>
                                <i class='fa fa-pencil'  title="冰柜编辑" @click="edit(item_)" :style="{'color':item_.fontColor3}"></i>
                                <i class='fa fa-user'  v-if="sCode!='tzjj'" @click="openLc(item_)" title="冷藏入柜" :style="{'color':item_.fontColor3}"></i>
                            </div>
                            <div style='font-size:12px;flex:1;text-align:center;line-height:30px'>{{item_.lc_dat1}}</div>
                            <div style='margin-right:5px;width:50px'>
                                <i class='fa fa-ban' v-if="sCode!='tzjj'" title="取消冷藏" @click="cancelRg(item_)" :style="{'color':item_.fontColor3}"></i>
                                <i class='fa fa-step-forward' v-if="sCode!='tzjj'"  @click="openCg(item_)" title="冷藏出柜" :style="{'color':item_.fontColor3}"></i>
                            </div>
                        </div>

                         <div class='box-footer' v-if="item_.sz_id==''">
                            <div style='width:80px'>
                                <i class='fa fa-pencil' title="冰柜编辑" @click="edit(item_)"></i>
                                <i class='fa fa-user-plus' v-if="sCode!='tzjj'" @click="openLc2(item_)" title="冷藏入柜"></i>
                            </div>
                            <div style='font-size:12px;flex:1;text-align:center;line-height:30px'></div>
                            <div style='width:50px;margin-right:5px'>
                                <i class='fa fa-ban'  v-if="sCode!='tzjj'"  @click="delItem(item_)"></i>
                                <i class='fa fa-cog'  v-if="sCode!='tzjj'" @click="setItem(item_)"></i>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
      
    </div>
</template>
<script>
export default {
    data(){
        return{
            items:[],
            src:"",
            appid:"",
            sCode:""
        }
    },
    created(){
         if(this.$route.query.appid){
            this.appid=this.$route.query.appid;
        }
        if(this.$route.query.dblclick){
            this.dblclick=this.$route.query.dblclick;
        }
        this.sCode=localStorage.getItem("sCode");
        this.loadData();
    },
    updated(){
        console.log("update======================")
    },
    methods:{
        loadData(){
            this.$post(this.appid,"byg/cold/readCabe",{}).then(data=>{
                this.items=data;
            });
        },
        initData(){
            this.loadData();
        },
        goSearch(){
            this.loadData();
        },
        add(){
            let data={};
            data.buttonName="新增冰柜"
            data.url="/commonEdit";
            data.fieldPath="lc_lg";
            data.filename2="殡仪馆系统/冷藏/冰柜";
            data.appid="business";
            this.$emit("openWin",JSON.stringify(data))
        },
        edit(item){
           /* let data={};
            data.buttonName="编辑冰柜"
            data.url="/commonEdit?sKey=86&fieldPath=lc_lg&filename2=殡仪馆系统/冷藏/冰柜&sId="+item.lg_id+"&appid=business";
            this.$emit("openWin",JSON.stringify(data))
            */
            let data={};
            data.buttonName="编辑冰柜"
            data.url="/commonEdit";
            data.fieldPath="lc_lg";
            data.sId=item.lg_id;
            data.filename2="殡仪馆系统/冷藏/冰柜";
            data.appid="business";
            this.$emit("openWin",JSON.stringify(data))
        },
        openLcdblClick(item){
            if(this.dblclick=="view"){
                let data={};
                data.buttonName="冷藏查看"
                data.url="/commonEdit";
                data.fieldPath="sz_info,lc_info";
                data.sId=item.lg_id;
                data.filename2="殡仪馆系统/冷藏/冷藏查看";
                data.appid="business";
                this.$emit("openWin",JSON.stringify(data))
            }else{
                let sz_id=item.sz_id;
                if(!sz_id){
                    return;
                }
                /*let data={};
                data.buttonName="冷藏入柜"

                data.url="/commonEdit?fieldPath=sz%255Finfo&filename2=殡仪馆系统/冷藏/冷藏入柜&sKey=29&company=&sId="+sz_id+"&modelId=3&title=业务管理&oldId=1&oldtitle=殡仪馆业务信息管理系统&appid=business";
                this.$emit("openWin",JSON.stringify(data))
                */
                let data={};
                data.buttonName="冷藏入柜"
                data.url="/commonEdit";
                data.fieldPath="sz_info,lc_info";
                data.sId=sz_id;
                data.filename2="殡仪馆系统/冷藏/冷藏入柜";
                data.appid="business";
                this.$emit("openWin",JSON.stringify(data))
            }
        },
        openLc(item){
           
            let sz_id=item.sz_id;
            if(!sz_id){
                return;
            }
            /*let data={};
            data.buttonName="冷藏入柜"

            data.url="/commonEdit?fieldPath=sz%255Finfo&filename2=殡仪馆系统/冷藏/冷藏入柜&sKey=29&company=&sId="+sz_id+"&modelId=3&title=业务管理&oldId=1&oldtitle=殡仪馆业务信息管理系统&appid=business";
            this.$emit("openWin",JSON.stringify(data))
            */
            let data={};
            data.buttonName="冷藏入柜"
            data.url="/commonEdit";
            data.fieldPath="sz_info,lc_info";
            data.sId=sz_id;
            data.filename2="殡仪馆系统/冷藏/冷藏入柜";
            data.appid="business";
            this.$emit("openWin",JSON.stringify(data))
           
        },
        openLc2(item){
            let lgId=item.lg_id;
            let data={};
            data.buttonName="冷藏入柜"
            data.url="/commonEdit";
            data.fieldPath="sz_info,lc_info";
            data.sId="";
            data.params={
                "lgId":lgId
            };
            data.param_key="lgId";
            data.filename2="殡仪馆系统/冷藏/冷藏入柜";
            data.appid="business";
            this.$emit("openWin",JSON.stringify(data))
        },
        openCg(item){
           
            let sz_id=item.sz_id;
            /*let data={};
            data.buttonName="冷藏出柜"

            data.url="/commonEdit?fieldPath=sz%255Finfo&filename2=殡仪馆系统/冷藏/冷藏出柜&sKey=29&company=&sId="+sz_id+"&modelId=3&title=业务管理&oldId=1&oldtitle=殡仪馆业务信息管理系统&appid=business";
            this.$emit("openWin",JSON.stringify(data))*/

            let data={};
            data.buttonName="冷藏出柜"
            data.url="/commonEdit";
            data.fieldPath="sz_info,lc_info";
            data.sId=sz_id;
            data.filename2="殡仪馆系统/冷藏/冷藏出柜";
            data.appid="business";
            this.$emit("openWin",JSON.stringify(data))
        },
        cancelRg(item){
            let sz_id=item.sz_id;
            this.$confirm('确定取消冷藏?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                   
                    this.$post("business","/api/view/delCommonEdit?filename=殡仪馆系统/冷藏/取消入柜&isSend=Y",{"ids":sz_id}).then(data=>{
                         if(data[0].status=="+OK"){
                            this.$message({
                                message: unescape(data[0].msg),
                                    type: 'success'
                                });
                            this.goSearch()
                        }else{
                            this.$alert(unescape(data[0].msg), '错误提示', {
                                confirmButtonText: '确定',
                                callback: action => {}
                            });
                        }
                    })
                }).catch(() => {
                         
            });
        },
        delItem(item){
            let loc_id=item.lg_id;
            this.$confirm('确定删除该冰柜?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                   
                    this.$post("business","/api/view/delCommonEdit?filename=殡仪馆系统/冷藏/冰柜删除&isSend=Y",{"ids":loc_id}).then(data=>{
                         if(data[0].status=="+OK"){
                            this.$message({
                                message: unescape(data[0].msg),
                                    type: 'success'
                                });
                            this.goSearch()
                        }else{
                            this.$alert(unescape(data[0].msg), '错误提示', {
                                confirmButtonText: '确定',
                                callback: action => {}
                            });
                        }
                    })
                }).catch(() => {
                         
            });
        },
        setItem(item){
            let loc_id=item.lg_id;
            let lg_status=item.lg_status;
            let msg="";
            let url="";
            if(lg_status=="A"){
                msg="确定要停用该冰柜?";
                url="/api/view/delCommonEdit?filename=殡仪馆系统/冷藏/冰柜设置/停用&isSend=Y"
            }else{
                msg="确定要启用该冰柜?";
                url="/api/view/delCommonEdit?filename=殡仪馆系统/冷藏/冰柜设置/启用&isSend=Y"
            }
            this.$confirm(msg, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                   
                    this.$post("business",url,{"ids":loc_id}).then(data=>{
                         if(data[0].status=="+OK"){
                            this.$message({
                                message: unescape(data[0].msg),
                                    type: 'success'
                                });
                            this.goSearch()
                        }else{
                            this.$alert(unescape(data[0].msg), '错误提示', {
                                confirmButtonText: '确定',
                                callback: action => {}
                            });
                        }
                    })
                }).catch(() => {
                         
            });
        }
    }
}
</script>
<style scoped>
   
    .cold{
        padding:10px;
        display: flex;
        flex-direction: column;
        overflow: auto;
    }
    .buttons{
        padding-bottom:10px;
    }
    .content{
        flex:1;
        overflow:auto;
    }
    .title{
        height:30px;
        border:1px solid #ddd;
        line-height:30px;
        margin-bottom:5px;
        padding:5px;
        border-radius:5px;
        background-color:cornflowerblue;
        color:#fff;
        padding-left:10px;
    }
    .item_contents{
        display:flex;
        flex-direction: row;
        flex-flow:row wrap ;
    }
    .box-card{
        width:200px;
        height:200px;
        display: flex;
        flex-direction: column;
        box-shadow:0 2px 12px 0 rgba(0,0,0,.1);
        border-radius: 5px;
        margin-right:10px;
        margin-top:10px;
    }
    .bg1{
        background:rgb(200, 215, 243);
    }
    .bg2{
        background:rgb(162, 247, 162);
    }
    .bg3{
        background:rgb(253, 184, 211);
    }
    .box-title{
        border-bottom:1px dashed cornflowerblue;
        height:50px;
        box-sizing: border-box;
        padding:10px;
    }
    .box-no{
        font-size:20px;
        color:cornflowerblue;
        font-weight: bold;
        float:left;
    }
    .box-name{
        float:right;
        font-size:13px;
    }
    
    .el-card__body{
        padding:0 !important;
        height:200px;
    }
    .box-content{
        padding:10px;
        font-size:14px;
        flex:1;
    }
    .box-footer{
        height:30px;
        border-top:1px dashed cornflowerblue;
        display:flex;
        flex-direction: row;
    }
    .box-footer i{
        color:cornflowerblue;
        margin-left:10px;
        cursor: pointer;
        line-height:30px
    }
    .isEdit i{
        color:rgb(34, 153, 34);
        margin-left:10px;
        cursor: pointer;
        line-height:30px
    }
    .waringwd{
        font-weight: bold;
        color:red;
    }
    .wd{
        font-weight:bold;
    }
</style>
